/*
 * @Descripttion: 
 * @version: 
 * @Author: hejin.gao
 * @Date: 2021-12-29 13:07:09
 * @LastEditors: hejin.gao
 * @LastEditTime: 2021-12-29 15:23:05
 */
/* eslint-disable */

const showSpaceDistance = (_viewer, layerId, objId, positions, plotBgColor) => {
  var text = _getMeasureTip(positions);
  let material;
  if (material == null) {
    material = new Cesium.PolylineGlowMaterialProperty({
      glowPower: 0.25,
      color: plotting.fullColor
    });
  }
  var dynamicPositions = new Cesium.CallbackProperty(function () {
    return positions;
  }, false);
  var num = positions.length;
  var last = positions[num - 1];
  var bData = {
    position: last,
    layerId,
    objId,
    shapeType: "SpaceDistance",
    label: {
      text,
      font: '16px "微软雅黑", Arial, Helvetica, sans-serif, Helvetica',
      fillColor: Cesium.Color.RED,
      outlineColor: Cesium.Color.SKYBLUE,
      outlineWidth: 1,
      style: Cesium.LabelStyle.FILL_AND_OUTLINE,
      heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
      disableDepthTestDistance: Number.POSITIVE_INFINITY
    },
    polyline: {
      positions: dynamicPositions,
      clampToGround: false,
      width: 8,
      material
    }
  };
  return _viewer.entities.add(bData);
}
function _getMeasureTip(pntList) {
  var dis3d = _computeLineDis3d(pntList);
  dis3d = dis3d.toFixed(3);
  var tip = "距离：" + dis3d + "千米";
  return tip;
}
function _computeDis2d(c1, c2) {
  var dis = Cesium.Cartesian2.distance(c1, c2) / 1000;
  return dis;
}
function _computeDis3d(p1, p2) {
  var dis = Cesium.Cartesian3.distance(p1, p2) / 1000;
  return dis;
}
function _computeLineDis3d(pntList) {
  var total = 0;
  for (var i = 1; i < pntList.length; i++) {
    var p1 = pntList[i - 1];
    var p2 = pntList[i];
    var dis = _computeDis3d(p1, p2);
    total += dis;
  }
  return total;
}

export {
  showSpaceDistance
}